package com.example.toutiao;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;

import com.example.toutiao.base.impl.ContentFragment;
import com.example.toutiao.base.impl.LeftMenuFragment;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public class MainActivity extends SlidingFragmentActivity {


    private static final String TAG_LEFT_MENU = "TAG_LEFT_MENU";
    private static final String TAG_CONTENT = "TAG_CONTENT";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        //添加侧边栏
        setBehindContentView(R.layout.left_menu);
        SlidingMenu slidingMenu = getSlidingMenu();
        //设置侧边栏出现的位置
        slidingMenu.setMode(slidingMenu.RIGHT);
        //全屏触摸
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        slidingMenu.setBehindOffset(0);

        initFragment();
    }

    /**
     * 输出化Fragment布局页面
     */
    public void initFragment(){
        //Fragment管理器
        FragmentManager fm = getSupportFragmentManager();
        //开启事务
        FragmentTransaction transaction = fm.beginTransaction();
        //将帧布局替换为对应的Fragment
        transaction.replace(R.id.fl_content, new ContentFragment(), TAG_LEFT_MENU);
        transaction.replace(R.id.fl_left_menu, new LeftMenuFragment(), TAG_CONTENT);

        //提交事务
        transaction.commit();
    }
}
